package com.orhon.smartcampus.modules.base.fetcher;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.orhon.smartcampus.modules.base.dao.PeriodsDao;
import com.orhon.smartcampus.modules.base.entity.Periods;
import com.orhon.smartcampus.modules.base.gqlModel.GQLPeriod;
import com.orhon.smartcampus.modules.base.mm.PeriodMapper;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;

@Component
public class PeriodFetcher implements DataFetcher {

    @Autowired
    PeriodsDao periodsDao;

    @Override
    public Object get(DataFetchingEnvironment env) throws Exception {
    	  int id = Integer.parseInt(env.getArgument("id").toString());

          String hql = "from Periods where deleted_at = null and id = "+id;
          Periods periods = periodsDao.findId(hql, null);
          if(periods!=null) {
          	  GQLPeriod gqlPeriod = PeriodMapper.MAPPER.toPeriods(periods);
              return gqlPeriod;
          }
  		return null;
    }


}
